package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TypeFeedback;
import com.ruoyi.system.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.UserFeedback;
import com.ruoyi.system.service.IUserFeedbackService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 问题反馈Controller
 *
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/feedback")
public class UserFeedbackController extends BaseController {
    @Autowired
    private IUserFeedbackService userFeedbackService;

    /**
     * 查询问题反馈列表
     */
    @RequiresPermissions("system:feedback:list")
    @GetMapping("/list")
    public TableDataInfo list(UserFeedback userFeedback) {
        startPage();
        List<UserFeedback> list = userFeedbackService.selectUserFeedbackList(userFeedback);
        return getDataTable(list);
    }

    /**
     * 导出问题反馈列表
     */
    @RequiresPermissions("system:feedback:export")
    @Log(title = "问题反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserFeedback userFeedback) {
        List<UserFeedback> list = userFeedbackService.selectUserFeedbackList(userFeedback);
        ExcelUtil<UserFeedback> util = new ExcelUtil<UserFeedback>(UserFeedback.class);
        util.exportExcel(response, list, "问题反馈数据");
    }

    /**
     * 获取问题反馈详细信息
     */
    @RequiresPermissions("system:feedback:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(userFeedbackService.selectUserFeedbackById(id));
    }

    /**
     * 新增问题反馈
     */
    @RequiresPermissions("system:feedback:add")
    @Log(title = "问题反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserFeedback userFeedback) {
        return toAjax(userFeedbackService.insertUserFeedback(userFeedback));
    }

    /**
     * 修改问题反馈
     */
    @RequiresPermissions("system:feedback:edit")
    @Log(title = "问题反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserFeedback userFeedback) {
        return toAjax(userFeedbackService.updateUserFeedback(userFeedback));
    }

    /**
     * 删除问题反馈
     */
    @RequiresPermissions("system:feedback:remove")
    @Log(title = "问题反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userFeedbackService.deleteUserFeedbackByIds(ids));
    }

    // 获取反馈类型列表
    @GetMapping("/userList")
    public List<TypeFeedback> selectTypeList() {
        List<TypeFeedback> list = userFeedbackService.selectTypeList();
        return list;
    }


    // 获取用户列表
    @RequestMapping("typeList")
    public List<User> selectUserList() {
        List<User> list = userFeedbackService.selectUserList();
        return list;
    }

    /**
     * 获取问题类型列表
     */
    @GetMapping("/type/list")
    public AjaxResult getTypeList() {
        try {
            List<TypeFeedback> list = userFeedbackService.selectTypeList();
            return AjaxResult.success(list);
        } catch (Exception e) {
            return AjaxResult.error("获取问题类型列表失败");
        }
    }
}
